package peer.webserver;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import peer.Config;

public class AppletServer implements Runnable{
	ServerSocket serverSocket=null;
	Thread mainThread;
	
	public static void main(String[] args) throws IOException{
		new AppletServer();
	}
	public AppletServer() {
		int i=0;
		while(true&i<10){
			i++;
			try {
				serverSocket=new ServerSocket(Config.appletPort);
				mainThread=new Thread(this);
				mainThread.start();
				break;
			} catch (IOException e) {
				//e.printStackTrace();
				Config.appletPort=peer.tools.RandomNum.randomInt(256*256);
				continue;
			}
		}
		
		
	}

	public void run() {
		while(true){
			try {
				Socket socket=serverSocket.accept();
				new AppletRequest(socket);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
}
